package com.usefullc.extinguisher.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.usefullc.common.enums.ValidActionEnum;
import com.usefullc.system.validator.UsefulValid;
import com.usefullc.extinguisher.domain.CheckStandard;
import com.usefullc.extinguisher.param.CheckStandardParam;
import com.usefullc.extinguisher.vo.CheckStandardVo;
import com.usefullc.extinguisher.query.CheckStandardQuery;
import com.usefullc.extinguisher.service.CheckStandardService;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.system.controller.BaseController;
import com.usefullc.system.controller.WebResultBuilder;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.entity.WebResult;
import com.usefullc.system.param.IdsParam;
import com.usefullc.system.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.validation.Valid;

import static com.usefullc.system.controller.WebResultBuilder.successResult;

/**
 * 检查标准控制类
 * @author: 星空
 * @date: 2022-11-19
 */
@RestController
@RequestMapping("/extinguisher/checkStandard/")
@Api( tags="检查标准")
public class CheckStandardController extends BaseController {

    @Autowired
    private CheckStandardService checkStandardService;

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "检查标准列表",response = WebResult.class)
    @GetMapping(path = "list",produces = "application/json")
    public WebResult list(@UsefulValid(query = true) CheckStandardQuery query) {
        Pager<CheckStandardVo> page = checkStandardService.findVoByPage(query);
        return WebResultBuilder.successResult(page);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "检查标准所有列表", response = WebResult.class)
    @GetMapping(path = "listAll", produces = "application/json")
    public WebResult listAll(@UsefulValid(query = true) CheckStandardQuery query) {
        List<CheckStandard> dataList = checkStandardService.findAll(query);
        return WebResultBuilder.successResult(dataList);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "获取树列表", response = WebResult.class)
    @GetMapping(path = "listTree", produces = "application/json")
    public WebResult listTree(CheckStandardQuery query) {
        List<TreeVo> dataList = checkStandardService.listTree(query);
        return WebResultBuilder.successResult(dataList);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "检查标准详情",response = WebResult.class)
    @GetMapping(path = "detail",produces = "application/json")
    public WebResult detail(@ApiParam(value = "示例ID") @Valid @RequestParam Long id) {
        CheckStandard checkStandard = checkStandardService.findById(id);
        return WebResultBuilder.successResult(checkStandard);
    }


    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "创建检查标准", response = WebResult.class)
    @PostMapping(path = "/save", produces = "application/json")
    @UsefulValid
    public WebResult save(@UsefulValid(save=true) @RequestBody CheckStandardParam param) {
        CheckStandard checkStandard = BeanUtils.beanCopy(param, CheckStandard.class);
        checkStandardService.saveCheckStandard(checkStandard);
        return WebResultBuilder.successResult(checkStandard);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "修改检查标准", response = WebResult.class)
    @PostMapping(path = "/update", produces = "application/json")
    public WebResult update(@UsefulValid(update=true) @RequestBody CheckStandardParam param) {
        CheckStandard checkStandard = BeanUtils.beanCopy(param, CheckStandard.class);
        checkStandardService.updateCheckStandard(checkStandard);
        return successResult();
    }
    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @PostMapping(path = "del",produces = "application/json")
    @ApiOperation(value = "删除检查标准",response = WebResult.class)
    public WebResult del(@UsefulValid(del=true) @RequestBody IdsParam idParam) {
        checkStandardService.delete(idParam.getIds());
        return WebResultBuilder.successResult();
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @PostMapping(path = "delByLogic",produces = "application/json")
    @ApiOperation(value = "逻辑删除检查标准",response = WebResult.class)
    public WebResult delByLogic(@UsefulValid(del=true) @RequestBody IdsParam idParam) {
        checkStandardService.delete(idParam.getIds());
        return WebResultBuilder.successResult();
    }






}
